<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class ArticleController extends Controller
{
        public function getList($pid)
        {
            $cateData = DB::table('article') -> where('pid', $pid) -> get();

            $data = [];
            foreach ($cateData as $key => $value) {
                $value -> sub = $this -> getList($value -> id);
                $data[] = $value;
            }

            return $data;

        }

        public function index($id = 1)
        {
            $data = $this -> getList(0);
            $sData = $this -> getList($id);

            return view('home.article.index',['title' => '中医药方','data' => $data,'sData' => $sData]);
        }
        public function detail($id)
        {
            $data = DB::table('article as a1')
                  -> select('a1.*','a2.article_detail','a2.created_at')
                  -> leftjoin('article_info as a2','a1.id','=','a2.pid')
                  -> where('a1.id',$id)
                  -> first();
            return view('home.article.detail',['title' => '文章详情','data' => $data]);
        }

}
